/**
 * 注册用户数据库模型
 */


const mongoose = require('mongoose')

const Schema = mongoose.Schema

const userSchema = new Schema({
  user_name: {
    type: String,
    //required:true,  //必传
		// 自定义错误信息 
    required: [true, '用户名不允许为空'],
    minlength: 2,  //规定传入的字符串的最小长度
    maxlength: 15, //规定传入的字符串的最大长度
    trim: true,  // 去除两边空格
  },
  user_id: {
    type: Number,
    required: [true, '用户id不允许为空'],
  },
  user_password: {
    type: String,
    required: [true, '用户密码不允许为空'],
    trim: true
  },
  user_age: {
    type: Number,
  },
  user_sex: {
    type: String,
    required: [true, '性别不允许为空'],
  },
  user_birthday: {
    type: String,
  },
  user_phone: {
    type: String,
    required: [true, '用户手机号不允许为空']
  },
  user_desc: {
    type: String,
    default: '添加简介(0-200字)',
    maxlength: 200
  },
  avatar_url: {
    type: String,
    default: 'http://127.0.0.1:5000/public/img/avatar/avatar.jpg'
  }
}, {
  timestamps: { createdAt: 'createTime', updatedAt: 'updateTime' }
})


const userModel = mongoose.model('User', userSchema)


module.exports = userModel


